package com.hly.musicbackground.model.admin.rest;

import com.hly.musicbackground.domain.Banner;
import com.hly.musicbackground.filter.AuthRoot;
import com.hly.musicbackground.model.index.service.BannerService;
import com.hly.musicbackground.model.index.service.impl.BannerServiceImpl;
import com.hly.musicbackground.model.music.params.IDParams;
import com.hly.musicbackground.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 管理端banner
 * */
@RestController
@RequestMapping("/api/admin/banner")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Api(tags = "管理端banner")
public class AdminBannerController {

    private final BannerService bannerService;

    /**
     * 获取banner
     * */
    @GetMapping("/list")
    @AuthRoot
    @ApiOperation(value = "获取banner")
    public Result get(@RequestParam(value = "type", defaultValue = "all") String type){
        return Result.ok(bannerService.lambdaQuery()
                .eq(!"all".equals(type), Banner::getType, type).list());
    }

    /**
     * 删除 banner
     * @param params 参数
     * */
    @PostMapping("/del")
    @AuthRoot
    @ApiOperation(value = "删除 banner")
    public Result del(@RequestBody IDParams params){
        bannerService.removeById(params.getId());
        return Result.ok();
    }

    /**
     * 添加/修改 banner
     * @param banner 参数
     * */
    @PostMapping("/edit")
    @AuthRoot
    @ApiOperation(value = "添加/修改 banner")
    public Result edit(@RequestBody Banner banner){
        return Result.ok(bannerService.saveOrSetBanner(banner));
    }

    /**
     * 设置启用/禁用 banner
     * @param params 参数
     * */
    @PostMapping("/status")
    @AuthRoot
    @ApiOperation(value = "设置启用/禁用 banner")
    public Result status(@RequestBody IDParams params){
        bannerService.setStatus(params.getId());
        return Result.ok();
    }
}
